package com.bt.lms.service.impl;

import com.bt.lms.bo.StudentList;
import com.bt.lms.dao.servise.StuStatusInfoDao;
import com.bt.lms.dao.servise.impl.StuStatusInfoDaoImpl;
import com.bt.lms.entity.StuBasicInfo;
import com.bt.lms.entity.page.Page;
import com.bt.lms.service.StuStatusInfoService;

import java.sql.SQLException;
import java.text.ParseException;

/**
 * 学籍信息模块功能实现
 */
public class StuStatusInfoServiceImpl implements StuStatusInfoService {
    @Override
    public Page<StudentList> pagingConditionQuery(Page<StudentList> page) throws SQLException {
        StuStatusInfoDao stuStatusInfoDao = new StuStatusInfoDaoImpl();
        String sql = "select r.id,r.req_code,r.name,r.gender,r.mobile_phone" +
                ",s.name as studyName,m.name as majorName,e.plan_name " +
                "from enp_plan as e right join reg_stu as r on r.id=e.id inner join major as m on m.id=e.id" +
                " inner join study_centre as s on s.id=r.id limit ?,?";
//        String sql = "select * from enp_plan limit ?,?";
        String sqlCount = "select count(id) from enp_plan";


        Page<StudentList> studentListPage = stuStatusInfoDao.selectPagingQuery(sql, sqlCount, page);


        return studentListPage;
    }

    @Override
    public Page<StudentList> infoQuery( Page page) throws SQLException {
        String sql = "select * from reg_stu where deleted = ? limit ?,?";
        String sqlCount = "select count(id) from reg_stu where deleted =?";
        StuStatusInfoDao stuStatusInfoDao = new StuStatusInfoDaoImpl();
        Page studentListPage = stuStatusInfoDao.infoQuery(sql, sqlCount, page);

        return studentListPage;
    }

    @Override
    public StuBasicInfo findDetails(Long id) throws SQLException, ParseException {

        //组建sql语句
        //学员基本信息
        //学员信息
        StuBasicInfo stuBasicInfo = new StuBasicInfo();

        String sql = "select * from stu_basic_info where id = ?";
        StuStatusInfoDao stuStatusInfoDao = new StuStatusInfoDaoImpl();
        stuStatusInfoDao.selectBasicInfo(sql, stuBasicInfo, id);


        //照片信息
        String sql1 = "select picture_path from picture_info where stu_basic_info_id = ?";
        stuStatusInfoDao.selectPictureInfo(sql1, stuBasicInfo, id);

        //扩展信息
        String sql2 = "select * from stu_extend_info where stu_basic_info_id = ?";
        stuStatusInfoDao.selectStuExtend(sql2, stuBasicInfo, id);

        //家庭成员信息
        String sql3 = "select * from family_member_info where stu_basic_info_id = ?";
        stuStatusInfoDao.selectFamilyMember(sql3, stuBasicInfo, id);

        //学籍基本信息
        String sql4 = "select * from stu_status_info where stu_basic_info_id = ?";
        stuStatusInfoDao.selectStuStatusInfo(sql4, stuBasicInfo, id);

        //注册信息
        String sql5 = "select * from register_info where stu_status_id = ?";
        stuStatusInfoDao.selectRegisterInfo(sql5, stuBasicInfo, id);

        //学籍异动信息
        String sql6 = "select * from transfer_info where stu_status_id = ?";
        stuStatusInfoDao.selectTransferInfo(sql6, stuBasicInfo, id);

        //就业信息
        String sql7 = "select * from employment_info where stu_status_id = ?";
        stuStatusInfoDao.selectEmploymentInfo(sql7, stuBasicInfo, id);


        return stuBasicInfo;
    }
}
